package com.jh.user.repository.freeQuick;

import com.jh.user.pojo.ChannelRate;
import com.jh.user.pojo.freeQuick.PassageWayRegister;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface PassageWayRegisterRepository extends JpaRepository<PassageWayRegister, Long>,
        JpaSpecificationExecutor<PassageWayRegister> {

    @Query("select f from PassageWayRegister f where f.requestNo =:requestNo and f.merchantNo =:merchantNo")
    PassageWayRegister findAllByRequestNoAndMerchantNo(@Param("requestNo")String requestNo, @Param("merchantNo")String merchantNo);

    @Query("select f from PassageWayRegister f where f.merchantNo = :merchantNo")
    List<PassageWayRegister> findByMerchantNo(@Param("merchantNo") String merchantNo);

    @Query("select p from PassageWayRegister p where p.userId = :userId and p.channelProductCode = :channelProductCode and p.registerState = '1'")
    PassageWayRegister findByUserIdAndChannelProductCode(@Param("userId") String userId, @Param("channelProductCode") String channelProductCode);

    @Query("select p from PassageWayRegister p where p.merchantNo = :merchantNo and p.channelProductCode = :channelNo")
    PassageWayRegister findByMerchantNoAndChannelProductCode(@Param("merchantNo") String merchantNo, @Param("channelNo") String channelNo);

    List<PassageWayRegister> findByUserId(String userId);

    PassageWayRegister findFirstByUserId(String userId);

    @Query("select p from PassageWayRegister p where p.userId = :userId")
    List<PassageWayRegister> queryByUserId(@Param("userId") String userId);
}
